package com.wifi.mvp.presenter;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.view.View;

import com.wifi.BaseApplication;
import com.wifi.eshipewifi.R;
import com.wifi.imp.MessageListener;

/**
 * Created by Administrator on 2017/8/1.
 */
public class BasePresenter<V> {
    public V mView;
    public BaseApplication application;
    public void attch(V mView){
        this.mView=mView;
    }


    public BaseApplication getmApplication(Activity activity){
        if(application==null)
            application = (BaseApplication) activity.getApplication();
        return application;
    }

    public void setListener(MessageListener listener){
        application.setMsgListener(listener);
    }

    public void setMessage(String msg){
        application.sendMsg(msg);
    }

    public void showAlertDialog(View view,Context context,String tittle,final String sendmsg){
        AlertDialog dialog= new AlertDialog.Builder(context)
                .setTitle(tittle)
                .setIcon(android.R.drawable.ic_dialog_info)
                .setView(view)
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
//                                application.sendMsg("$check_data;");
                        application.sendMsg(sendmsg);
                        dialog.cancel();
                    }
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                }).create();
        dialog .show();
    }



    public void detach() {
        mView = null;
//        if (mSubscription != null) {
//            mSubscription.unsubscribe();
//        }
    }
}
